package servletTestOne;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletTable extends HttpServlet {
	private String goods;

	public void init() throws ServletException {
		goods = "drink";
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		List<drink> drinkList = Arrays.asList(new drink("zhangsan", 18, 1, 2, 3, 4), new drink("lishi", 21, 1, 2, 3, 4),
				new drink("wanwu", 17, 1, 2, 3, 4), new drink("lixiao", 15, 1, 2, 3, 4),
				new drink("huda", 16, 1, 2, 3, 4));
		out.println("<h1>" + goods + "</h1>");
		out.println("<table border=1>");
		for (drink drink : drinkList) {
			out.print("<tr>");
			out.print("<td>");
			out.print(drink.getName());
			out.print("</td>");
			out.print("<td>");
			out.print(drink.getAge());
			out.print("</td>");
			out.print("<td>");
			out.print(drink.getSize());
			out.print("</td>");
			out.print("<td>");
			out.print(drink.getHeight());
			out.print("</td>");
			out.print("<td>");
			out.print(drink.getBreadth());
			out.print("</td>");
			out.print("<td>");
			out.print(drink.getCapacity());
			out.print("</td>");
			out.print("</tr>");
		}
	}

	class drink {
		private String name;
		private int age;
		private int size;
		private int height;
		private int breadth;
		private int capacity;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getAge() {
			return age;
		}

		public void setAge(int age) {
			this.age = age;
		}

		public int getSize() {
			return size;
		}

		public void setSize(int size) {
			this.size = size;
		}

		public int getHeight() {
			return height;
		}

		public void setHeight(int height) {
			this.height = height;
		}

		public int getBreadth() {
			return breadth;
		}

		public void setBreadth(int breadth) {
			this.breadth = breadth;
		}

		public int getCapacity() {
			return capacity;
		}

		public void setCapacity(int capacity) {
			this.capacity = capacity;
		}

		public drink(String name, int age, int size, int height, int breadth, int capacity) {
			super();
			this.name = name;
			this.age = age;
			this.size = size;
			this.height = height;
			this.breadth = breadth;
			this.capacity = capacity;
		}
	}
}
